import {
	INDEX_PAGE_URL, 
	INDEX_TAB_URL, 
	ACTIVITY_CONTENT_URL, 
	PLUS_URL, 
	CATALOG_URL, 
	COUPON_CENTER_URL,
	PRODUCT_DETAIL_URL
} from './url.js'
import http, {token} from './http';

const reqIndexPage = (pageId, storeNo) => {
	return http({
		method: 'post',
		url: INDEX_PAGE_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"storeNo": storeNo,
			"data": {
				// "pageId": 650703,
				// "pageId": 703634,
				// "pageId": 707667,
				"pageId": pageId
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('reqIndexPage-err---', err)
	})
}

const getIndexTab = (storeNo) => {
	return http({
		method: 'post',
		url: INDEX_TAB_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			// "storeNo": storeNo,
			"data": {
				"storeNo": storeNo,
				"status": 2
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('reqIndexTab-err---', err)
	})
}



const getActivityContent = (activityId) => {
	return http({
		method: 'post',
		url: ACTIVITY_CONTENT_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"isShowLoading": true,
			"userToken": token,
			"data": {
				"activityId": activityId,
				"storeNo": "133"
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getActivityContent-err---', err)
	})
}

const getPlus = (pageId, storeNo) => {
	return http({
		method: 'post',
		url: PLUS_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"isShowLoading": true,
			"userToken": token,
			"storeNo": storeNo,
			"data": {
				"pageId": pageId,
				"storeNo": storeNo
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getPlus-err---', err)
	})
}

const getCatalog = (catalogId, sortType, storeNo, page, sortDirection) => {
	return http({
		method: 'post',
		url: CATALOG_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"data": {
				"storeNo": storeNo,
				"catalogId": catalogId, //"10305",
				"sortType": sortType,
				"pageSize": 20,
				"page": page,
				"sortDirection": sortDirection  // 根据价格升级排序参数 1 是降序, 0 是升序 
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getCatalog-err---', err)
	})
}

const getCouponCenter = (couponId) => {
	return http({
		method: 'post',
		url: COUPON_CENTER_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"isShowLoading": true,
			"userToken": token,
			"data": {
				"pageNo": 1,
				"pageSize": 10,
				"couponId": couponId
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getCouponCenter-err---', err)
	})
}

const reqProductDetail = (productId, storeId) => {
	return http({
		method: 'post',
		url: PRODUCT_DETAIL_URL,
		data: {
			"appId": 1005,
			"apiVersion": "5.0",
			"userToken": token,
			"data": {
				"productClusterId": productId,
				"storeNo": storeId
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('reqProductDetail-err---', err)
	})
}

export {reqIndexPage, getIndexTab, getActivityContent, getPlus, getCatalog, getCouponCenter, reqProductDetail}